package com.coolingme.trycatch;

/**
 * try-with-resource
 *
 * @author wangyue
 * @date 2020/12/3 10:25
 */
public class TryDemo2 {

    public static void main(String[] args) {
        /*
        运行结果
        do something
        resource is closed
         */
        try (Resource res = new Resource()) {
            res.doSome();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}

class Resource implements AutoCloseable {
    void doSome() {
        System.out.println("do something");
    }

    @Override
    public void close() throws Exception {
        System.out.println("resource is closed");
    }

}
